<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<%@taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%
String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%>
<!DOCTYPE html>
<html>
<head>
<title></title>
<base href="<%=basePath%>">
<%@ include file="/base/jsp/include.jsp"%>
<script type="text/javascript">
	var grid;

	var delFun = function() {
		var rows = grid.datagrid('getSelections');
		if (rows.length == 0) {
			parent.$.messager.w('请选择需要删除的记录！');
			return;
		}
		parent.$.messager.confirm('询问', '您确定要删除此记录？', function(r) {
			if (r) {
				var ids = [];
				for ( var i = 0, l = rows.length; i < l; i++) {
					var r = rows[i];
					ids.push(r.id);
				}
				var c = ids.join(',');
				$.post(sy.contextPath + '/social/commentUpdate.do', {
					id : c,
					state:0
				}, function() {
					rows.length = 0;//必须，否则有bug
					grid.datagrid('reload');
				}, 'json');
			}
		});
	};
	
	function forbidden(type,id) {
		if (type == 1) {
			
			parent.$.messager.confirm('询问',"确定启用此楼层吗？", function(r) {
				if (r) {
					
					var data = {
						id : id,
						state : 1
					};
					SaveData(data);
				}
			});
		} else if(type == 0){
			parent.$.messager.confirm('询问',"确定删除此楼层吗？", function(r) {
				if (r) {
					var data = {
						id : id,
						state : 0
					};
					SaveData(data);
				}
			});
		}
	}
	
	function SaveData(data) {
		var url = sy.contextPath + '/social/commentUpdate.do';
		$.post(url, data, function() {
			grid.datagrid('reload');
		}, 'json');
	}
	
	$(function() {
		$('#state').combobox({   
			onSelect: function(rec){   
				grid.datagrid('load',sy.serializeObject($('#searchForm')));
	        } 
		});
		
		var menu;
		menu={	
				url : sy.contextPath + '/social/commentList.do',
				toolbar : '#toolbar',
				singleSelect : false,
				frozenColumns : [ [ {
					width : '10',
					align : 'center',
					field : 'id',
					checkbox : true
				}] ],
				columns : [ [ {
					width : $(this).width() * 0.15,
					title : '帖子',
					field : 'topicId',
					align : 'center',
					formatter : function(value, row, index) {
						return "<a href='javascript:;' title='点击只查看该帖子评论' onclick=\"showTopicComment('"+row.topicId+"')\">"+row.title+"</a>";
					}
				},{
					width : $(this).width() * 0.1,
					title : '楼层',
					field : 'floor',
					align : 'center',
					formatter : function(value, row, index) {
						return "#"+value;
					}
				},{
					width : $(this).width() * 0.1,
					title : '发帖人',
					field : 'account',
					align : 'center',
					formatter : function(value, row, index) {
						if(row.nickName!=null && row.nickName!=''){
							return value+"("+row.nickName+")";
						}
						return value;
					}
				},{
					width : $(this).width() * 0.2,
					title : '内容',
					field : 'content',
					align : 'center',
					formatter : function(value, row, index) {
						return "<span title='"+value+"'>"+value+"</span>";
					}
				},{
					width : $(this).width() * 0.2,
					title : '图集',
					field : 'imgs',
					align : 'center',
					formatter : function(value, row, index) {
						return po.showImg(value,18,18);
					}
				},
				/* {
					width : $(this).width() * 0.1,
					title : '主帖状态',
					field : 'topicState',
					align : 'center',
					formatter : function(value, row, index) {
						switch (value) {
						case 0:
							return '<img src="base/images/no.png"/>';
						case 1:
							return '<img src="base/images/yes.png"/>';
						}
					}
				}, */
				{
					width : $(this).width() * 0.1,
					title : '状态',
					field : 'state',
					align : 'center',
					formatter : function(value, row, index) {
						switch (value) {
						case 0:
							return '<a href="javascript:void(0);" onclick="forbidden(1,\''+row.id+'\')" ><img src="base/images/no.png" title="点击启用楼层" > </img></a>';
						case 1:
							return '<a href="javascript:void(0);" onclick="forbidden(0,\''+row.id+'\')" ><img src="base/images/yes.png"  title="点击删除楼层" > </img></a>';
						}
					}
				},
				{
					width : $(this).width() * 0.1,
					title : '创建时间',
					field : 'createTime',
					align : 'center'
				}
				] ]
			};
		
		grid = $('#grid').datagrid(menu);
	});
	function showTopicComment(id){
		$("#topicId").textbox("setValue",id);
		grid.datagrid('load',sy.serializeObject($('#searchForm')));
	}
</script>
</head>
<body class="easyui-layout" data-options="fit:true,border:false">
	<div id="toolbar" style="display: none;">
		<table>
			<tr>
				<td>
					<form id="searchForm">
						<table>
							<tr>
								<td>状态：</td>
								<td>
									<select id="state" name="state" editable="false" style="width:150px;" panelHeight='auto' data-options="valueField: 'value',textField: 'name',data: [{name: '在线',value: '1'},{name: '已删除',value: '0'}]"/>
								</td>
								<!-- <td>主帖状态：</td>
								<td>
									<select id="topicState" name="topicState" editable="false" style="width:150px;" panelHeight='auto' data-options="valueField: 'value',textField: 'name',data: [{name: '在线',value: '1'},{name: '已删除',value: '0'}]"/>
								</td> -->
								<td>用户账号：</td>
								<td>
									<input type="text" class="easyui-textbox" name="account" style="width: 150px"  />
								</td>
								<td>主帖ID：</td>
								<td>
									<input type="text" class="easyui-textbox" id="topicId" name="topicId" style="width: 150px"  />
								</td>
								<td>
									<a href="javascript:void(0);" class="easyui-linkbutton" data-options="iconCls:'ext-icon-zoom',plain:true" onclick="grid.datagrid('load',sy.serializeObject($('#searchForm')));">过滤</a>
									<a href="javascript:void(0);" class="easyui-linkbutton" data-options="iconCls:'ext-icon-zoom_out',plain:true" onclick="$('#searchForm input').val('');grid.datagrid('load',{});">重置过滤</a>
								</td>
							</tr>
						</table>
					</form>
				</td>
			</tr>
			<tr>
				<td>
					<table>
						<tr>
							<td><a href="javascript:void(0);" class="easyui-linkbutton" data-options="iconCls:'ext-icon-table_delete',plain:true" onclick="delFun();">删除</a></td>
						</tr>
					</table>
				</td>
			</tr>
		</table>
	</div>
	<div data-options="region:'center',fit:true,border:false">
		<table id="grid" data-options="fit:true,border:false"></table>
	</div>
</body>
</html>